allow wsh ai to attach directory listings to the chat#2469
Conversation
WalkthroughAdds first-class directory support across the AI chat stack: a new util/fileutil.ReadDir that returns rich directory metadata and truncation info; backend changes to treat directories as uploadable content (cmd/wsh/cmd/wshcmd-ai.go) and to produce/parse AttachedDirectoryListing tags in the OpenAI conversion layer (pkg/aiusechat/openai/openai-convertmessage.go); tools_readdir.go now delegates to fileutil.ReadDir and removes its previous DirEntryOut type; system prompt updated to document AttachedDirectoryListing; frontend ai-utils.ts includes a directory fileType/icon case. Several files adjusted to use absolute paths and JSON-encode directory listings. Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.5.0)Error: unknown linters: 'unusedfunc,unusedparams', run 'golangci-lint help linters' to see the list of supported linters Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (3)
pkg/util/fileutil/readdir.go (2)
60-79: Consider the symlink resolution cap behavior.The 1000-symlink cap is a reasonable performance safeguard. However, note that after 1000 symlinks, the function stops resolving symlink targets and uses
entry.IsDir()instead, which may return incorrect values for symlinks to directories. This creates potentially inconsistent sorting behavior within the same listing if you have more than 1000 symlinks.This is likely acceptable for the use case, but consider documenting this behavior if it's intentional.
96-120: Consider logging errors when entry.Info() fails.The function silently skips entries when
entry.Info()fails (lines 99-101). While this prevents the entire operation from failing due to a single problematic entry, it could be confusing if entries are missing due to permission issues or other errors.Consider logging these errors in development mode to aid debugging.
pkg/aiusechat/usechat.go (1)
70-72: Add punctuation for consistency.Line 71 is missing a period at the end, unlike Line 70. Consider adding one for consistency with the surrounding text style.
Apply this diff:
- "User-attached directories use the tag <AttachedDirectoryListing_xxxxxxxx directory_name="...">JSON DirInfo</AttachedDirectoryListing_xxxxxxxx>", + "User-attached directories use the tag <AttachedDirectoryListing_xxxxxxxx directory_name=\"...\">JSON DirInfo</AttachedDirectoryListing_xxxxxxxx>.",
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (6)
cmd/wsh/cmd/wshcmd-ai.go(3 hunks)frontend/app/aipanel/ai-utils.ts(12 hunks)pkg/aiusechat/openai/openai-convertmessage.go(2 hunks)pkg/aiusechat/tools_readdir.go(2 hunks)pkg/aiusechat/usechat.go(1 hunks)pkg/util/fileutil/readdir.go(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
pkg/aiusechat/openai/openai-convertmessage.go (2)
pkg/aiusechat/openai/openai-backend.go (1)
OpenAIMessageContent(66-78)pkg/aiusechat/uctypes/usechat-types.go (2)
UIMessagePart(35-68)UIMessageDataUserFile(70-75)
cmd/wsh/cmd/wshcmd-ai.go (1)
pkg/util/fileutil/readdir.go (1)
ReadDir(38-137)
pkg/util/fileutil/readdir.go (1)
pkg/util/utilfn/utilfn.go (1)
FormatRelativeTime(1114-1154)
pkg/aiusechat/tools_readdir.go (1)
pkg/util/fileutil/readdir.go (1)
ReadDir(38-137)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: Analyze (go)
- GitHub Check: Build for TestDriver.ai
🔇 Additional comments (13)
frontend/app/aipanel/ai-utils.ts (1)
78-80: LGTM! Directory icon handling added.The directory type check correctly returns the folder icon, consistent with the new directory attachment feature.
pkg/util/fileutil/readdir.go (5)
18-36: LGTM! Well-structured type definitions.The types are appropriately designed for JSON serialization with proper use of
omitemptyfor optional fields.
38-51: LGTM! Path validation is correct.The function properly expands the home directory, validates the path exists, and ensures it's a directory before proceeding.
81-88: LGTM! Sorting logic is correct.Directories are sorted first, then entries are sorted alphabetically. The use of the cached
isDirMapavoids redundant lookups.
90-94: LGTM! Truncation logic is correct.The function properly preserves the total entry count before truncation and sets the truncated flag.
122-136: LGTM! Result construction is correct.The function properly constructs the result and handles the root directory edge case where
filepath.Dirwould return the same path.pkg/aiusechat/openai/openai-convertmessage.go (3)
370-393: LGTM! Directory conversion logic is correct.The directory handling properly mirrors the text file conversion logic with appropriate defaults and encoding.
396-396: LGTM! Error message updated correctly.The error message now accurately reflects support for directories.
533-551: LGTM! Directory listing UI conversion is correct.The directory tag parsing properly mirrors the text file handling and correctly creates a
data-userfilepart with thedirectorymime type.cmd/wsh/cmd/wshcmd-ai.go (3)
112-115: LGTM! Absolute path logic correctly placed.Getting the absolute path before the directory check is appropriate since both files and directories need it.
117-136: LGTM! Directory handling is correct.The directory reading logic properly uses
fileutil.ReadDirand marshals the result to JSON. The hard-codedmaxEntriesof 500 matches the default intools_readdir.go.One observation: Both files and directories now use absolute paths as
fileName(lines 127, 134), which provides full context but may be verbose in the UI. This appears intentional and consistent.
139-148: LGTM! MIME type logic correctly handles directories.The updated condition properly prevents directories from being coerced to
text/plain, and the binary content check appropriately skips directories.pkg/aiusechat/tools_readdir.go (1)
53-82: LGTM! Refactoring correctly delegates to fileutil.ReadDir.The function properly uses the centralized directory reading utility and constructs an appropriate map-based response with helpful truncation messaging.
No description provided.